define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'agentgoods/index' + location.search,
                    add_url: 'agentgoods/add',
                    edit_url: 'agentgoods/edit',
                    del_url: 'agentgoods/del',
                    multi_url: 'agentgoods/multi',
                    import_url: 'agentgoods/import',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'seckill.name', title: __('秒杀时间'), operate: 'LIKE'},
                        // {field: 'category_id', title: __('Category_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'original_price', title: __('Original_price'), operate:'BETWEEN'},
                        {field: 'image', title: __('封面图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'price', title: __('抢购价'), operate:'BETWEEN'},
                        // {field: 'employ_ids', title: __('Employ_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'city', title: __('City'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'views', title: __('Views')},
                            // {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'freight_id', title: __('Freight_id')},
                        // {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        // {field: 'agent_day', title: __('Agent_day')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'employ.name', title: __('Employ.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'freight.name', title: __('Freight.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Template.helper("Fast", Fast);
                $(document).on("fa.event.appendfieldlist", "#second-table .btn-append", function (e, obj) {
                    //绑定动态下拉组件
                    Form.events.selectpage(obj);
                    //绑定日期组件
                    Form.events.datetimepicker(obj);
                    //绑定上传组件
                    Form.events.faupload(obj);

                    //上传成功回调事件，变更按钮的背景
                    $(".upload-image", obj).data("upload-success", function (data) {
                        $(this).css("background-image", "url('" + Fast.api.cdnurl(data.url) + "')");
                    })
                });

                Form.api.bindevent($("form[role=form]"));
            }


        }
    };
    return Controller;
});
